﻿#include	"Engine.System.hpp"

namespace Engine { namespace System {

	Time & Time::operator=(const Time & iOther) {
		nYear		= iOther.nYear;
		nMonth		= iOther.nMonth;
		nDay		= iOther.nDay;
		nWeek		= iOther.nWeek;
		nHour		= iOther.nHour;
		nMinute		= iOther.nMinute;
		nSecond		= iOther.nSecond;
		nMilliSec	= iOther.nMilliSec;
		nUnixSec	= iOther.nUnixSec;

		return (* this);
	}

	Time Time::Convert(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSecond) {
		Time		iInfo;
		struct tm	iTime;

		iTime.tm_year	= nYear - 1900;
		iTime.tm_mon	= nMonth - 1;
		iTime.tm_mday	= nDay;
		iTime.tm_hour	= nHour;
		iTime.tm_min	= nMin;
		iTime.tm_sec	= nSecond;
		
		iInfo.nUnixSec	= mktime(&iTime);
		iInfo.nYear		= nYear;
		iInfo.nMonth	= nMonth;
		iInfo.nDay	 	= nDay;
		iInfo.nWeek		= iTime.tm_wday;
		iInfo.nHour		= nHour;
		iInfo.nMinute	= nMin;
		iInfo.nSecond	= nSecond;
		iInfo.nMilliSec	= 0;

		return std::move(iInfo);
	}

}}

namespace Engine { namespace System { namespace Path {

	std::string PurePath(const std::string & szFullPath) {
		if (szFullPath.empty() || szFullPath.length() <= 0) return "";
		for (int nIdx = szFullPath.length() - 1; nIdx >= 0; --nIdx) {
			if (szFullPath[nIdx] == '/' || szFullPath[nIdx] == '\\') {
				if (nIdx != 0) return szFullPath.substr(0, nIdx);
			}
		}
		return "./";
	}

	std::string PureFile(const std::string & szFullPath) {
		if (szFullPath.empty() || szFullPath.length() <= 0) return "";
		for (int nIdx = szFullPath.length() - 1; nIdx >= 0; --nIdx) {
			if (szFullPath[nIdx] == '/' || szFullPath[nIdx] == '\\') {
				return szFullPath.substr(nIdx + 1);
			}
		}
		return szFullPath;
	}

}}}
